package com.ktjiaoyu.service.impl;

import com.ktjiaoyu.entity.StorageRecord;
import com.ktjiaoyu.mapper.StorageRecordMapper;
import com.ktjiaoyu.service.StorageRecordService;
import com.ktjiaoyu.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/12/20  11:38
 */
@Service("storageRecordService")
public class StorageRecordServiceImpl implements StorageRecordService {
    @Autowired
    private StorageRecordMapper storageRecordMapper;

    @Override
    public Page<StorageRecord> findPage(StorageRecord storageRecord, Integer pageNo, Integer pageSize) {
        Page<StorageRecord> page=new Page<>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        //总记录数
        Integer count=storageRecordMapper.countRecord(storageRecord);
        page.setTotalCount(count);
        Integer pageBegin=(pageNo-1)*pageSize;
        List<StorageRecord> data=storageRecordMapper.getPageList(storageRecord,pageBegin,pageSize);
        page.setData(data);
        return page;
    }

    @Override
    public boolean insert(StorageRecord storageRecord) {
        return storageRecordMapper.insert(storageRecord)>0;
    }

    @Override
    public boolean update(StorageRecord storageRecord) {
        return storageRecordMapper.update(storageRecord)>0;
    }

    @Override
    public StorageRecord selectById(Long id) {
        return storageRecordMapper.selectById(id);
    }

    @Override
    public StorageRecord selectCode(String srCode) {
        return storageRecordMapper.selectCode(srCode);
    }

    @Override
    public boolean delete(Long id) {
        return storageRecordMapper.delete(id)>0;
    }
}
